﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;

namespace Triax.Modules.Department
{
    /// -----------------------------------------------------------------------------
    ///<summary>
    /// The Controller class for the DommainHosting
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    public class DommainHostingController : ISearchable, IPortable
    {

    #region Constructors

        public DommainHostingController()
        {
        }

    #endregion

    #region Public Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// adds an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objDommainHosting">The DommainHosting object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddDommainHosting(DommainHosting objDommainHosting)
        {
           // if (objDommainHosting.DommainHostingName.Trim() != "")
            {
                DataProvider.Instance().AddDommainHosting(objDommainHosting.ModuleId,
                    

objDommainHosting.TenNhaIn,
objDommainHosting.Diachi,
objDommainHosting.SoDienThoai,
objDommainHosting.Fax,
objDommainHosting.MST,
objDommainHosting.STK,
objDommainHosting.NguoiPhuTrach,
objDommainHosting.Other,
objDommainHosting.InsertDate,
objDommainHosting.UpdateDate,
objDommainHosting.CreateByUser,
objDommainHosting.UpdateByUser,
objDommainHosting.IsDelete,
objDommainHosting.tempInt1,
objDommainHosting.tempInt2,
objDommainHosting.tempInt3,
objDommainHosting.tempInt4,
objDommainHosting.tempStr1,
objDommainHosting.tempStr2,
objDommainHosting.tempStr3,
objDommainHosting.tempStr4,
objDommainHosting.tempDate1,
objDommainHosting.tempDate2

                    );
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// deletes an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeleteDommainHosting(int ModuleId, int DommainHostingId) 
        {
            DataProvider.Instance().DeleteDommainHosting(ModuleId,DommainHostingId);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public DommainHosting GetDommainHosting(int ModuleId, int DommainHostingId)
        {
            return CBO.FillObject<DommainHosting>(DataProvider.Instance().GetDommainHosting(ModuleId, DommainHostingId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public List<DommainHosting> GetDommainHostings(int ModuleId)
        {
            return CBO.FillCollection< DommainHosting >(DataProvider.Instance().GetDommainHostings(ModuleId));
        }

        public List<DommainHosting> GetDommainHostingsByCond(int ModuleId, string cond,string sql)
        {
            return CBO.FillCollection<DommainHosting>(DataProvider.Instance().GetDommainHostingsByCond(ModuleId,cond,sql));
        }

        public List<DommainHosting> GetDommainHostingsByCond_count(int ModuleId, string cond, string sql)
        {
            return CBO.FillCollection<DommainHosting>(DataProvider.Instance().GetDommainHostingsByCond_count(ModuleId, cond, sql));
        }

        //return CBO.FillCollection<GIayChungNhanInfo>(DataProvider.Instance().GetProductsByCond_Count(ModuleId, Cond, Sql));

        public List<DommainHosting> GetDommainHostingsByCond_PhanTrang(int currPage, int recodperpage, int Pagesize, string Cond, string Sql)
        {
            return CBO.FillCollection<DommainHosting>(DataProvider.Instance().GetDommainHostingsByCond_PhanTrang(currPage, recodperpage, Pagesize, Cond, Sql));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// saves an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objDommainHosting">The DommainHosting object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdateDommainHosting(DommainHosting objDommainHosting)
        {
           // if (objDommainHosting.DommainHostingName.Trim() != "")
            {
                DataProvider.Instance().UpdateDommainHosting(objDommainHosting.ModuleId, 
                    
objDommainHosting.DommainHostingId,
objDommainHosting.TenNhaIn,
objDommainHosting.Diachi,
objDommainHosting.SoDienThoai,
objDommainHosting.Fax,
objDommainHosting.MST,
objDommainHosting.STK,
objDommainHosting.NguoiPhuTrach,
objDommainHosting.Other,
objDommainHosting.InsertDate,
objDommainHosting.UpdateDate,
objDommainHosting.CreateByUser,
objDommainHosting.UpdateByUser,
objDommainHosting.IsDelete,
objDommainHosting.tempInt1,
objDommainHosting.tempInt2,
objDommainHosting.tempInt3,
objDommainHosting.tempInt4,
objDommainHosting.tempStr1,
objDommainHosting.tempStr2,
objDommainHosting.tempStr3,
objDommainHosting.tempStr4,
objDommainHosting.tempDate1,
objDommainHosting.tempDate2


                    );
            }
        }
        // End kết hợp xử lý
    #endregion

    #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetSearchItems implements the ISearchable Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {
            SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
            List<DommainHosting> colDommainHostings  = GetDommainHostings(ModInfo.ModuleID);

            foreach (DommainHosting objDommainHosting in colDommainHostings)
            {
                if(objDommainHosting != null)
                {
                    SearchItemInfo SearchItem = new SearchItemInfo( );
                    SearchItemCollection.Add(SearchItem);
                }
            }

            return SearchItemCollection;
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be exported</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleID)
        {
            string strXML = "";
            List<DommainHosting> colDommainHostings  = GetDommainHostings(ModuleID);

            if (colDommainHostings.Count != 0)
            {
                strXML += "<DommainHostings>";
                foreach (DommainHosting objDommainHosting in colDommainHostings)
                {
                    strXML += "<DommainHosting>";
                    strXML += "<content>" + XmlUtils.XMLEncode(objDommainHosting.tempStr1) + "</content>";
                    strXML += "</DommainHosting>";
                }
                strXML += "</DommainHostings>";
            }

            return strXML;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            XmlNode xmlDommainHostings = Globals.GetContent(Content, "DommainHostings");

            foreach (XmlNode xmlDommainHosting in xmlDommainHostings.SelectNodes("DommainHosting"))
            {
                DommainHosting objDommainHosting = new DommainHosting();

                objDommainHosting.ModuleId = ModuleID;
            //    objDommainHosting.DommainHostingName = xmlDommainHosting.SelectSingleNode("content").InnerText;
          //      objDommainHosting.CreatedByUser = UserId;
                AddDommainHosting(objDommainHosting);
            }

}

    #endregion

    }
}

